﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using King.Engine.GameObjects;
using Microsoft.Xna.Framework;
using King.Engine.Components;
using BreacherCreature.GameObjects.Tiles;

namespace BreacherCreature.GameObjects
{
    public abstract class Character : AnimatedGameObject<CharacterAnimations>
    {
        static float WALK_TIMEOUT = .1f;

        float curWalk = 0;

        #region Constructor

        public Character(Dictionary<CharacterAnimations, Animation> animations, CharacterAnimations initialAnimation)
            : base(animations, initialAnimation)
        {
            AddComponent<CollisionPusher<SightBlocker>>();
        }

        #endregion


        #region Protected Methods

        protected override void UpdateBeforeComponents(GameTime gameTime)
        {
            if (curWalk > 0)
            {
                curWalk -= (float)gameTime.ElapsedGameTime.TotalSeconds;
                if (curWalk <= 0)
                    SetAnimation(CharacterAnimations.Idle);
            }

            base.UpdateBeforeComponents(gameTime);
        }

        protected void Move(Vector2 direction, int speed, GameTime gameTime)
        {
            if (curWalk <= 0)
                SetAnimation(CharacterAnimations.Walk);
            curWalk = WALK_TIMEOUT;
            float scale = (float)(speed * gameTime.ElapsedGameTime.Milliseconds) / 1000f;
            Bounds.Offset((int)(scale * direction.X), (int)(scale * direction.Y));
        }

        #endregion

    }
}
